package cn.edu.sdjzu.xg.eagle.xg23_kcsj_01.controller;

import cn.edu.sdjzu.xg.eagle.xg23_kcsj_01.entity.Patent;
import cn.edu.sdjzu.xg.eagle.xg23_kcsj_01.result.Result;
import cn.edu.sdjzu.xg.eagle.xg23_kcsj_01.service.PatentService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
@RestController
@RequestMapping("/zlgl")
public class PatentController {

    @Autowired
    private PatentService patentService;

    @PostMapping("/patent")
    public Result addPatent(@RequestBody Patent patent) {
        if (patentService.addPatent(patent)) {
            return Result.success("增加成功");
        } else {
            return Result.error("001", "增加失败");
        }
    }

    @DeleteMapping("/patent/{PatentId}")
    public Result deletePatent(@PathVariable Long PatentId) {
        if (patentService.deletePatent(PatentId)) {
            return Result.success("删除成功");
        } else {
            return Result.error("002", "删除失败");
        }
    }

    @PutMapping("/patent")
    public Result updatePatent(@RequestBody Patent patent) {
        if (patentService.updatePatent(patent)) {
            return Result.success("更新成功");
        } else {
            return Result.error("003", "更新失败");
        }
    }

    // 模糊条件分页查询
    @PostMapping("/search")
    public Result selectPatentsByCondition(
            @RequestParam(defaultValue = "1") Integer pageNum,
            @RequestParam(defaultValue = "10") Integer pageSize,
            @RequestBody(required = false) Patent patent) {
        PageInfo<Patent> pageInfo = patentService.selectPatentsByCondition(pageNum, pageSize, patent);
        return Result.success(pageInfo);
    }


}
